package com.ybwh.springboot1.util;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * httpweb 工具类
 * </p>
 *
 * @author ybwh
 * @since 2019年5月17日 下午2:28:17
 */
public class HttpWebUtil {

	/**
	 * 判断请求是否为Ajax
	 * 
	 * @param request HttpServletRequest
	 * @return true or false
	 */
	public static boolean isAjaxRequest(HttpServletRequest request) {
		String ajaxPostReqHead = request.getHeader("X-Requested-With");
		String ajaxGetReqHead = request.getHeader("RequestType");
		if (ajaxPostReqHead != null && !"".equals(ajaxPostReqHead) && ajaxPostReqHead.equals("XMLHttpRequest")
				|| (ajaxGetReqHead != null && !"".equals(ajaxGetReqHead) && ajaxGetReqHead.equalsIgnoreCase("ajax"))) {
			return true;
		} else {
			return false;
		}
	}

}
